<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>爱丁堡数据管理平台登录</title>
    <!-- Bootstrap Core CSS -->
    <link href="style/bootstrap.min.css" rel="stylesheet">
    <link href="style/bootstrap-extension.css" rel="stylesheet">
    <!-- animation CSS -->
    <link href="style/animate.css" rel="stylesheet">
    <!-- Custom CSS -->
    <link href="style/style.css" rel="stylesheet">
    <link href="style/css.css" rel="stylesheet">
    <!-- color CSS -->
    <link href="style/megna.css" id="theme" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="layui/css/layui.css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <script type="text/javascript" src="js2/respond.min.js"></script>
    <script type="text/javascript" src="js2/html5shiv.js"></script>
    <script type="text/javascript" src="layui/layui.js"></script>
</head>

<body>
    <!-- Preloader -->
    <div class="preloader">
        <div class="cssload-speeding-wheel"></div>
    </div>
    <section id="wrapper" class="login">
        <div class="login-box">
            <div class="white-box">
                <a href="javascript:void(0)" class="text-center db">
                    <img src="images/logo_new.png" alt="Home" />
                    <br />
                    <h4>爱丁堡糖尿病国际中心IT平台</h4>
                </a>
                <form class="form-horizontal form-material" id="loginform" onsubmit="login();return false;">
                    <h3 class="box-title m-b-20"></h3>
                    <div class="form-group ">
                        <div class="col-xs-12">
                            <input class="form-control" type="text" required="" id="uname" name="uname" placeholder="请输入账号名"></div>
                    </div>
                    <div class="form-group">
                        <div class="col-xs-12">
                            <input class="form-control" type="password" required="" id="pwd" name="pwd" placeholder="请输入密码" autocomplete="no">
                        </div>
                    </div>
                    <div class="form-group" id='mobileDiv' style="display: none;">
                        <div class="col-xs-12">
                            <input class="form-control" type="hidden" id="mobile" name="mobile" placeholder="请输入手机号">
                        </div>
                    </div>
                    <!-- <div class="form-group" id='codeDiv' style="display: none;">
                        <div class="col-xs-12">
                           <input class="form-control" type="hidden" required="" id="code" name="code" placeholder="验证码(4位)">
                        </div>
                    </div> -->
                    <div class="form-group" id='user_jzDiv'>
                        <div class="col-md-12">
                            <div class="checkbox checkbox-info pull-left p-t-0">
                                <input id="checkbox-signup" name="user_jz" id="user_jz" type="checkbox" checked="checked">
                                <label for="checkbox-signup"> 记住我 </label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group text-center m-t-20">
                        <div class="col-xs-12">
                            <!--
                            <button class="btn btn-info btn-lg btn-block waves-effect waves-light" type="submit" id="btn"  onclick="login()">log in</button>
                            -->
                            <button class="btn btn-info btn-lg btn-block waves-effect waves-light" type="submit" id="btn">登录</button>
                        </div>
                    </div>
                    <!-- <div class="form-group m-b-0">
                        <div class="col-sm-12 text-center">
                            <p style="text-align: right;"><a href="javascript:void(0)" onclick='noAccount(this);' id='navigation' type='register'>没有账号？</a></p>
                        </div>
                    </div> -->
                </form>
            </div>
        </div>
    </section>
    <!-- jQuery -->
    <script src="js2/jquery.min.js"></script>
    <!-- Bootstrap Core JavaScript -->
    <script src="js2/tether.min.js"></script>
    <script src="js2/bootstrap.min.js"></script>
    <script src="js2/bootstrap-extension.min.js"></script>
    <!-- Menu Plugin JavaScript -->
    <script src="js2/sidebar-nav.min.js"></script>
    <!--slimscroll JavaScript -->
    <script src="js2/jquery.slimscroll.js"></script>
    <!--Wave Effects -->
    <script src="js2/waves.js"></script>
    <!-- Custom Theme JavaScript -->
    <script src="js2/custom.min.js"></script>
    <!--Style Switcher -->
    <script src="js2/jQuery.style.switcher.js"></script>
    <script type="text/javascript">
    layui.use('layer', function() {
        layer = layui.layer;
    });

    function login() {
        var uname = $('#uname').val();
        var pwd = $('#pwd').val();
        var mobile = $('#mobile').val();
        var code = $('#code').val();
        var user_jz = $("input[name='user_jz']").prop("checked");
        var type = $('#navigation').attr('type');
        if (type == 'login') {
            if (!(/^[0-9a-zA-Z_]{6,18}$/.test(pwd))) {
                layer.msg('密码格式错误(必须是6-18个英文字母、数字或下划线组成)', { icon: 2 });
                return;
            }
            if (!(/^1[34578]\d{9}$/.test(mobile))) {
                layer.msg('手机格式错误', { icon: 2 });
                return;
            }
            $.ajax({
                type: "POST",
                url: urlS + "/users/",
                data: { 'username': uname, 'password': pwd, 'mobile': mobile, 'code': code },
                dataType: 'json',
                success: function(data) {
                    if (data.token) {
                        localStorage['tokenSSS'] = data.token;
                        location.href = '../../../index.html';
                        layer.msg(data.msg);
                    } else {
                        layer.msg(data.msg);
                    }
                },
                error: function(jqXHR, textStatus, errorThrown) {
                    var errData = JSON.parse(jqXHR.responseText).msg;
                    for (var i in errData) {
                        console.log(JSON.stringify(errData[i]));
                        layer.msg(JSON.stringify(errData[i]).split(',')[0].split(':')[1].split('"')[1], { icon: 2 });
                        break;
                    }
                }
            });
        } else {
        	// loginSS();
            if (user_jz) {
                localStorage['uname'] = uname;
                //$.cookie('uname',uname,{expires:7, path: '/'});
            } else {
                localStorage['uname'] = '';
                //$.cookie('uname','',{expires:7, path: '/'});
            }
            $.ajax({
                type: "POST",
                url: "http://localhost:8083/SublimeText3Project/yayi/json/index/user/login",
                data: { 'username': uname, 'password': pwd },
                dataType: 'json',
                success: function(data) {
                    // console.log(data);
                    if (data.AresToken) {
                        localStorage['AresToken'] = JSON.stringify(data.AresToken);
                        localStorage['LogOnResult'] = JSON.stringify(data.LogOnResult);
                        window.location.href = "http://localhost:8083/yayi";
                    } else {
                        layer.msg(data.msg);
                    }
                },
                error: function(jqXHR, textStatus, errorThrown) {
                    layer.msg("服务器未知错误!", { icon: 2 });
                    // if (jqXHR && jqXHR.responseText) {
                    //     var errData = JSON.parse(jqXHR.responseText);
                    //     for (var i in errData) {
                    //         layer.msg(JSON.stringify(errData[i]).split('"')[1], { icon: 2 });
                    //         break;
                    //     }
                    // } else {
                    //     layer.msg("服务器未知错误!", { icon: 2 });
                    // }
                }
            });
        }
    }

    function noAccount(t) {
        var t = $(t);
        $('#zname').val('');
        if (t.attr('type') == 'register') {
            $('#uname').val('');
            $('#pwd').val('');
            $('#mobileDiv').css('display', 'block');
            $('#mobileDiv input[type="hidden"]').attr('type', 'text');
            // $('#codeDiv').css('display','block');
            // $('#codeDiv input[type="hidden"]').attr('type','text');
            $('#user_jzDiv').css('display', 'none');
            $('#btn').text('注册');
            t.attr('type', 'login').text('去登录');
        } else {
            $('#uname').val('');
            $('#pwd').val('');
            $('#mobileDiv').css('display', 'none');
            $('#mobileDiv input[type="hidden"]').attr('type', 'hidden');
            // $('#codeDiv').css('display','none');
            // $('#codeDiv input[type="hidden"]').attr('type','hidden');
            $('#user_jzDiv').css('display', 'block');
            $('#btn').text('登录');
            t.attr('type', 'register').text('没有账号？');
        }
    }
    $(function() {
        //var cookname=$.cookie('uname');
        $('#uname').val(localStorage['uname']);
    });

    // function loginSS() {
    //     localStorage['LogOnResult'] = '{"ExtraData":{"DashboardRoleType":"前台","UserDashboardConfig":{"RoleId":0,"Type":1,"ConfigData":[{"Type":1,"Items":[{"Name":"todayCheck","Description":null,"Value":"true"},{"Name":"todayAccount","Description":null,"Value":"true"},{"Name":"uncharge","Description":null,"Value":"true"},{"Name":"charged","Description":null,"Value":"true"},{"Name":"followup","Description":null,"Value":"true"},{"Name":"unconfirmAppt","Description":null,"Value":"true"},{"Name":"cancelAppt","Description":null,"Value":"true"},{"Name":"pendingAppt","Description":null,"Value":"true"},{"Name":"brith","Description":null,"Value":"false"},{"Name":"appointApply","Description":null,"Value":"true"},{"Name":"expirationRemind","Description":null,"Value":"true"}],"Blocks":[{"Name":"newRegister","Description":null,"Value":"true"},{"Name":"newAppointment","Description":null,"Value":"true"},{"Name":"todayVisit","Description":null,"Value":"true"},{"Name":"totalCharge","Description":null,"Value":"true"},{"Name":"followupCount","Description":null,"Value":"true"},{"Name":"smsCount","Description":null,"Value":"false"}]}]},"UserRoles":"公司管理员,牙医,前台","UserOffices":[12,60,61,62]},"State":0,"User":{"TenantId":"130bed17-fed1-4976-9343-c66d0f0a800b","Id":179,"Account":"test","IsRoot":false,"RoleType":"公司管理员","IsNeedExtraValidate":false,"IsNeedDeviceValidate":false,"ExtraValidationMobile":null,"ExtraValidationToken":null,"Provider":{"RelatedProviderId":null,"EmployeeNo":"001","WorkingOffices":[{"Id":12,"Name":"测试","Abbreviation":"单店环境","Address":null,"PhoneNumber":null,"PictureId":0,"Point":0,"ParentId":0,"OfficeType":0,"BizType":0,"ExpiredDate":null},{"Id":60,"Name":"总部","Abbreviation":"总部","Address":null,"PhoneNumber":null,"PictureId":0,"Point":0,"ParentId":-1000,"OfficeType":1,"BizType":0,"ExpiredDate":null},{"Id":61,"Name":"全球齿科连锁","Abbreviation":"全球","Address":null,"PhoneNumber":null,"PictureId":0,"Point":0,"ParentId":60,"OfficeType":0,"BizType":0,"ExpiredDate":null},{"Id":62,"Name":"2","Abbreviation":"2","Address":null,"PhoneNumber":null,"PictureId":0,"Point":0,"ParentId":60,"OfficeType":0,"BizType":0,"ExpiredDate":null}],"IsIntern":false,"Name":"测试专用号","Job":"管理员","Title":null,"Department":null,"Mobile":"15396059250","Show":false,"OfficeId":60,"Id":181},"Roles":[{"Id":158,"Name":"公司管理员","IsTenantAdministrator":true},{"Id":161,"Name":"牙医","IsTenantAdministrator":false},{"Id":163,"Name":"前台","IsTenantAdministrator":false}],"LoginOffices":[{"Id":12,"Name":"测试","Abbreviation":"单店环境","Address":null,"PhoneNumber":null,"PictureId":0,"Point":0,"ParentId":0,"OfficeType":0,"BizType":0,"ExpiredDate":null},{"Id":60,"Name":"总部","Abbreviation":"总部","Address":null,"PhoneNumber":null,"PictureId":0,"Point":0,"ParentId":-1000,"OfficeType":1,"BizType":0,"ExpiredDate":null},{"Id":61,"Name":"全球齿科连锁","Abbreviation":"全球","Address":null,"PhoneNumber":null,"PictureId":0,"Point":0,"ParentId":60,"OfficeType":0,"BizType":0,"ExpiredDate":null},{"Id":62,"Name":"2","Abbreviation":"2","Address":null,"PhoneNumber":null,"PictureId":0,"Point":0,"ParentId":60,"OfficeType":0,"BizType":0,"ExpiredDate":null}]},"TenantId":"130bed17-fed1-4976-9343-c66d0f0a800b","TenantName":"林飞培训专用","LoginOfficeId":12,"OfficeName":"测试","OfficeType":0,"BusinessType":1,"ExpiredDate":null,"BusinessEdition":"Edition.Ultimate40","IsRootGroup":true,"LogOnMode":0,"NeedValidationCode":false,"IsCheckMobileValidation":false,"ValidationMobile":null,"DeviceId":null,"IsAres3Enabled":true,"IsAres2Disabled":false,"SelectedVersion":"3.0","AccountLogId":110301,"IsGhost":false}';
    //     localStorage["AresToken"] = '{"token_type":"bearer","api_host":"http://localhost:8083","access_token":"V9smPuNTLo9eXYlAsPrXUMm2ubvZguGZLUILoCuBLz2D1kBOcMGBn6Kd0GNC_w7Z-KGtv_1g8-w4EOcbG2Hs3QmNjV8LtTbHUpHA4Z-Thruydigl5V0GErEukVIWhjpgf3seN3Gy_NSrqik3ipb-DNauMjXwYBOE_z3gk784F3DYzWqxoWYQLlR5FTmXZNV6-z2asBCAoygXrs3sTgpT1M5UHt9jcdwE6K0ls7tnmn20uqqkLzm-0OWYI5CkOwf1aQ1OQAfybbweqjhsPXsxeLzDIFwGfUfzjqk9qhpzzNwnCzamOMrpjA6pUTOc1nxK"}';
    //     window.location.href = "http://localhost:8083/yayi";
    // }
    </script>
</body>

</html>